package com.tanhua.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.model.domain.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/10 10:07
 */
public interface LogMapper extends BaseMapper<Log> {

    @Select("SELECT count(DISTINCT(user_id)) from tb_log where type = #{type} AND log_time = #{logTime}")
    Integer qurryTypeAndLogTime(@Param("type") String type, @Param("logTime") String logTime);

    // 根据统计时间
    @Select("SELECT COUNT(DISTINCT(user_id)) FROM tb_log where log_time = #{logTime}")
    Integer queryByLogTime(String logTime);

    /**
     * 查询次日留存， 从昨日的活跃用户中获取今日的活跃用户
     * @param today
     * @param yestoday
     * @return
     */

    @Select("SELECT COUNT(DISTINCT(user_id)) FROM tb_log where log_time = #{today} " +
            "AND user_id in(SELECT user_id from tb_log where log_time = #{yestoday} AND type = \"0102\")")
    Integer queryNumRetention1d(@Param("today") String today, @Param("yestoday") String yestoday);
}
